<html>
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <h1 data-lake-id="dlLnw" id="dlLnw"><span data-lake-id="u018013d4" id="u018013d4">典型回答</span></h1>
  <p data-lake-id="u19b627db" id="u19b627db"><br></p>
  <p data-lake-id="u5e9cf396" id="u5e9cf396"><span data-lake-id="uf6a13f0e" id="uf6a13f0e">RocketMQ 支持两种消息模式：</span><strong><span data-lake-id="u7a3d1d0d" id="u7a3d1d0d">广播消费（ Broadcasting ）</span></strong><span data-lake-id="u9e3d292e" id="u9e3d292e">和</span><strong><span data-lake-id="uc26b64a7" id="uc26b64a7">集群消费（ Clustering ）</span></strong><span data-lake-id="ua4a70b0f" id="ua4a70b0f">。</span></p>
  <p data-lake-id="u1dc42fa1" id="u1dc42fa1"><br></p>
  <p data-lake-id="ua2802917" id="ua2802917"><strong><span data-lake-id="uadd2f0fa" id="uadd2f0fa">广播消费</span></strong><span data-lake-id="uab25695b" id="uab25695b">：当使用广播消费模式时，RocketMQ 会将每条消息推送给集群内所有的消费者，保证消息至少被每个消费者消费一次。</span></p>
  <p data-lake-id="ucbf8901f" id="ucbf8901f"><span data-lake-id="u1b9b5bf8" id="u1b9b5bf8">​</span><br></p>
  <p data-lake-id="ucd043c76" id="ucd043c76"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1693629100005-d004fc86-c2da-4100-8a47-218cbec2b8be.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_37%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u67b5c316" id="u67b5c316"><br></p>
  <p data-lake-id="u4acce55e" id="u4acce55e"><span data-lake-id="u27a0d584" id="u27a0d584">广播模式下，RocketMQ 保证消息至少被客户端消费一次，但是并不会重投消费失败的消息，因此业务方需要关注消费失败的情况。并且，客户端每一次重启都会从最新消息消费。客户端在被停止期间发送至服务端的消息将会被自动跳过。</span></p>
  <p data-lake-id="ufa0d7506" id="ufa0d7506"><br></p>
  <p data-lake-id="u6f7bebd4" id="u6f7bebd4"><strong><span data-lake-id="u9c319bb6" id="u9c319bb6">集群消费</span></strong><span data-lake-id="udfe19ea5" id="udfe19ea5">：当使用集群消费模式时，RocketMQ 认为任意一条消息只需要被集群内的任意一个消费者处理即可。</span></p>
  <p data-lake-id="u7ecf7809" id="u7ecf7809"><span data-lake-id="ubb454134" id="ubb454134">​</span><br></p>
  <p data-lake-id="u088ecb71" id="u088ecb71"><img src="https://cdn.nlark.com/yuque/0/2023/png/5378072/1693629162403-f7934694-18bb-41e4-9871-26b95c76b8d6.png?x-oss-process=image%2Fwatermark%2Ctype_d3F5LW1pY3JvaGVp%2Csize_40%2Ctext_SmF2YSA4IEd1IFA%3D%2Ccolor_FFFFFF%2Cshadow_50%2Ct_80%2Cg_se%2Cx_10%2Cy_10"></p>
  <p data-lake-id="u8e18d5f1" id="u8e18d5f1"><br></p>
  <p data-lake-id="u2ca7a7b9" id="u2ca7a7b9"><span data-lake-id="u6c545cae" id="u6c545cae">集群模式下，每一条消息都只会被分发到一台机器上处理。但是不保证每一次失败重投的消息路由到同一台机器上。一般来说，用集群消费的更多一些。</span></p>
  <p data-lake-id="uc4adaea1" id="uc4adaea1"><span data-lake-id="u6c909475" id="u6c909475">​</span><br></p>
  <p data-lake-id="u1cb1b24c" id="u1cb1b24c"><span data-lake-id="u3324c654" id="u3324c654">通过设置MessageModel可以调整消费方式：</span></p>
  <p data-lake-id="ud037f001" id="ud037f001"><span data-lake-id="uea1ee312" id="uea1ee312" class="lake-fontsize-11">​</span><br></p>
  <pre lang="java"><code>
// MessageModel设置为CLUSTERING（不设置的情况下，默认为集群订阅方式）。
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.CLUSTERING);


// MessageModel设置为BROADCASTING。
properties.put(PropertyKeyConst.MessageModel, PropertyValueConst.BROADCASTING); 
</code></pre>
 </body>
</html>